package com.boofie.blog.exception;

import com.boofie.blog.model.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author boofie
 * @date 2021/8/20 21:28
 */
@RestControllerAdvice
@Slf4j
public class GlobalException {
    @ExceptionHandler(NullPointerException.class)
    public R nullPointerException(Exception e){
        log.error("空指针异常:{}",ExceptionUtils.getMessage(e));
        return R.error().message(e.getMessage());
    }
    @ExceptionHandler(Exception.class)
    public R globalException(Exception e){
        log.error("未知异常:{}",ExceptionUtils.getMessage(e));
        return R.error().message(e.getMessage());
    }
}
